package util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * 文件操作工具类
 *
 * @author 大定府羡民（QQ：1032694760）
 */
public class FileUtils {

    private FileUtils() {
        super();
    }

    public static boolean existsFile(String filePath) {
        return Files.exists(Paths.get(System.getProperty("user.dir"), filePath));
    }

    public static String readFromFile(String filePath) {
        try {
            return Files.readString(Paths.get(System.getProperty("user.dir"), filePath));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void saveToFile(String filePath, String content) {
        try {
            Files.writeString(Paths.get(System.getProperty("user.dir"), filePath), content, StandardOpenOption.CREATE);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
